﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GIMS.MODEL;
using KPIS.GERP.GIMS.IDAL;

namespace KPIS.GERP.GIMS.DAL
{
    public sealed class BgmProjectDAL : IDALBgmProject
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public BgmProjectDAL()
        {

        }

        public BgmProjectInfo GetBgmProject(int seq)
        {
            string strSQL;
            DataSet ds;
            DataRowCollection dr;
            BgmProjectInfo info = new BgmProjectInfo();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@seq", seq);

                strSQL = "SELECT *"
                        + " FROM BGM_PROJECT"
                        + " WHERE BGM_PROJ_SEQ = @seq";

                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);
                dr = ds.Tables[0].Rows;
                if (dr.Count > 0)
                {
                    RecordInfo infoRecord = new RecordInfo();
                    SysRecordStatusInfo infoStatus = new SysRecordStatusInfo();
                    info.Seq = Convert.ToInt32(dr[0]["BGM_PROJ_SEQ"]);
                    info.Name = (dr[0]["BGM_PROJ_NAME"]).ToString();
                    info.Descr = (dr[0]["BGM_PROJ_DESCR"]).ToString();
                    infoRecord.Created_by = (Convert.IsDBNull(dr[0]["CREATED_BY"]) ? null : (Nullable<int>)(dr[0]["CREATED_BY"]));
                    infoRecord.Created_when = (Convert.IsDBNull(dr[0]["CREATED_WHEN"]) ? null : (Nullable<DateTime>)(dr[0]["CREATED_WHEN"]));
                    infoRecord.Updated_by = (Convert.IsDBNull(dr[0]["UPDATED_BY"]) ? null : (Nullable<int>)(dr[0]["UPDATED_BY"]));
                    infoRecord.Updated_when = (Convert.IsDBNull(dr[0]["UPDATED_WHEN"]) ? null : (Nullable<DateTime>)(dr[0]["UPDATED_WHEN"]));
                    infoStatus.Status = (dr[0]["RECORD_STATUS"]).ToString();
                    infoRecord.InfoStatus = infoStatus;
                    info.InfoRecord = infoRecord;
                }
            }
            catch (Exception ex)
            {
                throw (ex);
                //return null;
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }


    }
}
